<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form-model layout="horizontal"  ref="form"  :label-col="labelCol" :wrapper-col="wrapperCol"  :model="model" >

        <a-form-model-item label="物料名称" required prop="name" hasFeedback>
          <a-input v-model="model.name"    placeholder="请输入物料名称"/>
        </a-form-model-item>

        <a-form-model-item label="物料编码" required prop="materialCode" hasFeedback>
          <a-input v-model="model.materialCode"    placeholder="请输入物料编码"/>
        </a-form-model-item>

        <a-form-model-item label="适用机型" required  prop="applicableModel" hasFeedback>
          <a-input v-model="model.applicableModel"    placeholder="输入适用机型"/>
        </a-form-model-item>

        <a-form-model-item label="工装版本"  prop="fixtureVer" hasFeedback>
          <a-input v-model="model.fixtureVer" placeholder="输入工装版本"/>
        </a-form-model-item>

        <a-form-model-item label="产品版本"  prop="prodVer" hasFeedback >
          <a-input  v-model="model.prodVer"  placeholder="请输入产品版本" />
        </a-form-model-item>

        <a-form-model-item label="电压"  prop="voltage" hasFeedback >
          <a-input  v-model="model.voltage"  placeholder="电压" />
        </a-form-model-item>

        <a-form-model-item label="功率"  prop="power" hasFeedback >
          <a-input  v-model="model.power"  placeholder="功率" />
        </a-form-model-item>

      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import { httpAction,getAction } from '@api/manage'

export default {
  name: 'MaterialCodeModal',
  data () {
    return {
      title:"操作",
      visible: false,
      model: {},
      layout: {
        labelCol: { span: 3 },
        wrapperCol: { span: 14 },
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 3 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      url: {
        add: "/baseInfo/materialCtrl/add",
        // edit: "/test/jeecgDemo/edit",
      },
    }
  },
  created () {
  },
  methods: {
    add () {
      this.edit({});
    },
    edit (record) {
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    close () {
      this.$refs.form.resetFields();
      this.$emit('close');
      this.visible = false;
    },
    handleOk () {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if(!this.model.id){
            httpurl+=this.url.add;
            method = 'post';
          }else{
            httpurl+=this.url.edit;
            method = 'put';
          }
          httpAction(httpurl,this.model,method).then((res)=>{
            if(res.success){
              that.$message.success(res.message);
              that.$emit('ok');
            }else{
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
            that.close();
          })
        }
      })
    },
    handleCancel () {
      this.close()
    }
  }


}
</script>

<style scoped>

</style>